package cn.stylefeng.guns.modular.yingbao.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.yingbao.entity.SysUser;
import cn.stylefeng.guns.modular.yingbao.entity.UserMy;
import cn.stylefeng.guns.modular.yingbao.model.params.SysUserParam;
import cn.stylefeng.guns.modular.yingbao.service.SysUserService;
import cn.stylefeng.guns.modular.yingbao.service.UserMyService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import oracle.jdbc.proxy.annotation.Post;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 盈宝用户表控制器
 *
 * @author zs
 * @Date 2019-12-10 10:25:15
 */
@CrossOrigin
@Controller
@RequestMapping("/sysUser")
@Api(tags = "用户模块")
public class SysUserController extends BaseController {

    private String PREFIX = "/sysUser";

    @Autowired
    private SysUserService sysUserService;
    @Autowired
    private UserMyService userMyService;


    /**
     * 跳转到主页面
     *
     * @author zs
     * @Date 2019-12-10
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/sysUser.html";
    }

    /**
     * 新增页面
     *
     * @author zs
     * @Date 2019-12-10
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/sysUser_add.html";
    }

    @ApiOperation("注册")
    @PostMapping("login")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "account" ,value = "账号"),//**
            @ApiImplicitParam(name = "password" ,value = "密码"),//**
            @ApiImplicitParam(name = "name" ,value = "名字"),
            @ApiImplicitParam(name = "birthday" ,value = "生日(年月日)"),
            @ApiImplicitParam(name = "sex" ,value = "性别"),
            @ApiImplicitParam(name = "email" ,value = "电子邮箱"),
            @ApiImplicitParam(name = "phone" ,value = "电话"),//***
            @ApiImplicitParam(name = "referrerCode" ,value = "推荐码"),
            @ApiImplicitParam(name = "salt",value = "验证码")//***
    })
    public ResponseData addLogin(SysUser user){
        return sysUserService.addLogin(user);
    }

    @ApiOperation("登录")
    @PostMapping("index")
    @ResponseBody
    @ApiImplicitParam(name = "account",value = "用户名")
    public ResponseData queryByAndPassword(String account,String password){
        return sysUserService.queryByNameAndPassword(account,password);
    }

    @ApiOperation("忘记密码")
    @PostMapping("forgetPassword")
    @ResponseBody
    @CrossOrigin
    public ResponseData forgetPassword(String account,String phone,String code,String password){
        return sysUserService.forgetPassword(account,phone,code,password);
    }

    /**
     * 编辑页面
     *
     * @author zs
     * @Date 2019-12-10
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/sysUser_edit.html";
    }

    /**
     * 新增接口
     *
     * @author zs
     * @Date 2019-12-10
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(SysUserParam sysUserParam) {
        this.sysUserService.add(sysUserParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author zs
     * @Date 2019-12-10
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(SysUserParam sysUserParam) {
        this.sysUserService.update(sysUserParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author zs
     * @Date 2019-12-10
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(SysUserParam sysUserParam) {
        this.sysUserService.delete(sysUserParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author zs
     * @Date 2019-12-10
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(SysUserParam sysUserParam) {
        SysUser detail = this.sysUserService.getById(sysUserParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author zs
     * @Date 2019-12-10
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(SysUserParam sysUserParam) {
        return this.sysUserService.findPageBySpec(sysUserParam);
    }

    /**
     *有无资金密码
     * @param account
     * @param phone
     * @return
     */
    @ApiOperation("有无资金密码")
    @PostMapping("queryByMoneyAndPhoneSeekMoneyPassword")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "account",value = "账号名"),
        @ApiImplicitParam(name = "phone",value = "手机号")
    })
    @ResponseBody
    public ResponseData queryByMoneyAndPhoneSeekMoneyPassword(String account,String phone){
        return this.sysUserService.queryByNameAndPhoneSeekMoneyPassword(account,phone);
    }

    /*@PostMapping("addMoneyPassword")
    @ResponseBody
    @ApiOperation()*/

    @PostMapping("upMoneyPassword")
    @ApiOperation("修改资金密码")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "account",value = "用户名"),
            @ApiImplicitParam(name = "phone",value = "手机号"),
            @ApiImplicitParam(name = "code",value = "验证码"),
            @ApiImplicitParam(name = "moneyPassword",value = "原先资金密码"),
            @ApiImplicitParam(name = "newMoneyPassword",value = "现在资金密码")
    })
    public ResponseData upMoneyPassword(String account,String phone,String code,String moneyPassword,String newMoneyPassword){
        return this.sysUserService.upMoneyPassword(account,phone,code,moneyPassword,newMoneyPassword);
    }


    @PostMapping("YZM")
    @ApiOperation("手机接收验证码")
    @ResponseBody
    @ApiImplicitParam(name = "phone",value = "手机号")
    public ResponseData queryByPhone(String phone){
        return this.sysUserService.queryByPhone(phone);
    }

    @PostMapping("queryByMoneyPassword")
    @ApiOperation("验证资金密码")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id" , value = "主键id"),
            @ApiImplicitParam(name = "moneyPassword" , value = "资金密码")
    })
    public ResponseData queryByMoneyPassword(Long id,String moneyPassword){
        return this.sysUserService.queryByMoneyPassword(id,moneyPassword);
    }

}


